package edu.whu.tao.constant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.whu.tao.util.JsonBuilder;

/**
 * 
 * <P>实体状态枚举</P>
 * @author 陶焕(13294175866)
 * @date 2016年5月21日 上午11:08:01
 */
public enum ModelStateEnum {

	NORMAL(0,"正常"),
	DELETE(-1,"删除");
	
	private Integer id;
	
	private String name;
	
	

	private ModelStateEnum(Integer id, String name) {
		this.id = id;
		this.name = name;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public static ModelStateEnum getById(Integer id){
		for(ModelStateEnum tmpEnum:ModelStateEnum.values()){
			if(tmpEnum.getId()==id){
				return tmpEnum;
			}
		}
		return null;
	}
	
	public static ModelStateEnum getByName(String name){
		for(ModelStateEnum tmpEnum:ModelStateEnum.values()){
			if(tmpEnum.getName().equalsIgnoreCase(name)){
				return tmpEnum;
			}
		}
		return null;
	}
	
	public static String toJsonArray(boolean isSearch){
		List<Map<String, Object>> results = new ArrayList<Map<String,Object>>();
		if(isSearch){
			Map<String, Object> result = new HashMap<String, Object>();
			result.put(CommonConstants.COMBO_ID, CommonConstants.STR_EMPTY);
			result.put(CommonConstants.COMBO_TEXT, CommonConstants.STR_ALL);
			results.add(result);
		}
		for(ModelStateEnum tmpEnum:ModelStateEnum.values()){
			Map<String, Object> result = new HashMap<String, Object>();
			result.put(CommonConstants.COMBO_ID, tmpEnum.getId());
			result.put(CommonConstants.COMBO_TEXT, tmpEnum.getName());
			results.add(result);
		}
		return JsonBuilder.toJson(results);
	}
	
}
